package com.zb.framework.wechatnews.common;

import com.zb.framework.common.constant.StatusCode;
import com.zb.framework.common.entity.ResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * 全局异常拦截处理类,处理系统出现的各种异常，并统一封装返回提示
 * @author 李文龙
 *
 */
//@RestControllerAdvice
public class GlobalDefaultExceptionHandler
{
    final static Logger logger = LoggerFactory.getLogger(GlobalDefaultExceptionHandler.class);
    
    /**
     * 处理业务异常
     * @param req
     * @param e
     * @return
     */
    //@ExceptionHandler(value = BusiException.class)
    //@ResponseBody
    public ResponseEntity busiErrorHandler(HttpServletRequest req, Exception e)
    {
    	ResponseEntity ret = ResponseEntity.build(StatusCode.INVALID_REQUEST, "业务处理错误", null);
    	logger.error(e.toString(),e);
        return ret;
    }

    /**
     * 处理默认的系统异常，即没有封装自定义异常的情况下就到该方法处理
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResponseEntity defaultErrorHandler(HttpServletRequest req, Exception e)
    {
    	ResponseEntity ret = ResponseEntity.build(StatusCode.SERVER_ERROR, "服务器内部错误", null);
        logger.error(e.toString(),e);
        return ret;
    }
    

}
